﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString.Count != 0)
        {
            string username = Request.QueryString["username"];
            string password = Request.QueryString["password"];

            string str = "Data Source=.;Initial Catalog=blog;Persist Security Info=True;User ID=sa;Password=nihao!1";
            //连接数据库的字符串
            using (SqlConnection conn = new SqlConnection(str))//连接数据库
            {
                conn.Open();//打开
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "select * from  UserInfo where name= @username and password= @password ";//查询输入的内容
                    cmd.Parameters.Add(new SqlParameter("username", username));//获取
                    cmd.Parameters.Add(new SqlParameter("password", password));
                    //cn.Parameters.Add(new SqlParameter());
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            Response.Write("登录成功!");
                            Response.End();
                        }
                        else
                        {
                            Response.Write("<script>alert('登录失败');</script> ");
                            Response.End();
                        }

                    }
                }
            }

        }




        //conn.Open();

        //conn.Close(); 
    }
}